package com.junchenrobot.mes.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * 参数验证配置
 *
 * @author SeaWave
 * @date 2022/10/19
 */
@Configuration
public class ValidationConfiguration {
    
    /**
     * 开启快速验证失败模式
     *
     * @return {@link Validator}
     */
    @Bean
    public Validator validator() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                                                      .configure()
                                                      .failFast(true)
                                                      .buildValidatorFactory();
        return validatorFactory.getValidator();
    }
    
}
